package com.wd.tech.view.activity;

import android.content.SharedPreferences;
import android.util.Log;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.tech.R;
import com.wd.tech.adapter.News.NewsDetailsChannelAdapter;
import com.wd.tech.base.BaseActivity;
import com.wd.tech.base.BasePresenter;
import com.wd.tech.bean.News_Show_Bean;
import com.wd.tech.mvp.IPresenterImpl;
import com.wd.tech.url.BaseUrl;

import java.util.HashMap;
import java.util.Map;

public class News_ChannelActivity extends BaseActivity {


    private RecyclerView chann;
    private NewsDetailsChannelAdapter newsDetailsChannelAdapter;
    private TextView channelte;

    @Override
    protected void initData() {

        SharedPreferences newsid = getSharedPreferences("Channelid", MODE_PRIVATE);
        int channel_id = newsid.getInt("Channel_id", 0);
        Log.e("频道id",channel_id+"");
        Map<String ,Object> map = new HashMap<>();
        map.put("id",channel_id);
        Map<String ,Object> show = new HashMap<>();
        show.put("Id",channel_id);
        show.put("page",1);
        show.put("count",15);
        mPresenter.PresenterGetNewsChanner(BaseUrl.News_Sh,show, News_Show_Bean.class);
        mPresenter.PresenterGetNewsChanner(BaseUrl.News_Sh,map,News_Show_Bean.class);
        chann.setLayoutManager(new LinearLayoutManager(News_ChannelActivity.this));

    }

    @Override
    protected void initView() {
        chann = findViewById(R.id.channel);
        channelte = findViewById(R.id.channel_text);
    }

    @Override
    protected BasePresenter initPresenter() {
        return new IPresenterImpl();
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_news_channel;
    }

    @Override
    public void success(Object o) {

        if (o instanceof News_Show_Bean){
            newsDetailsChannelAdapter = new NewsDetailsChannelAdapter(News_ChannelActivity.this,((News_Show_Bean)o).getResult());
            chann.setAdapter(newsDetailsChannelAdapter);
        }

    }

    @Override
    public void Error(Throwable throwable) {

    }
}
